 (require 'class)
(require 'eieio)
 
(defvar *class-pool* '())
(defvar *current-class* 'nil)


(defun add-class (class)
  "add a class object to class pool."
  (if (assoc-string (oref class name) *class-pool* 't)
      (class-replace class)
    (push (list (oref class name) class) *class-pool*)))

(defun class-replace (class)
  (let* ((position (position (assoc-string (oref class name) *class-pool* 't)
			      *class-pool*)))
    (setf (elt *class-pool*  position)
	  (list (oref class name) class))))



(defun get-classes ()
  "load classes in the class pool."
  *class-pool*)

(defun get-class-names ()
  (let ((name-list '()))
    (dolist (class-alist *class-pool*)
      (push (elt class-alist 0) name-list))
    name-list))

(defun has-class-p (classname)
  "return if we has the class"
  (if (assoc-string classname *class-pool* 't)
      't
    nil))

(defun get-class(class-name)
  "return class according to the class-name"
  (if (setq class-instance (assoc-string class-name *class-pool* 't))
      (elt class-instance 1)
    nil))

(defun clear-pool ()
  (setq *class-pool* nil))

(defun set-current-class (class)
  (add-class class)
  (setq *current-class* class))

(defun refresh-current-class (class)
  (add-class class)
  (setq *current-class* class))

(defun get-current-class ()
  *current-class*)

(defun print-class (classname)
  (interactive "sclass name: ")
  (let* ((class-instance nil))
    (setq class-instance (get-class classname))
    (when class-instance
      (print (concat (oref class-instance name) "    :   " (oref class-instance path)) )
      (dolist (var (oref class-instance variables))
	(print var)
	;(print (concat (oref var name) " : " (oref var type)))
	)
      (dolist (fun (oref class-instance functions))
	(print fun)
	;(print (concat (oref fun name) " : " (oref fun return-type)))
	))))
(provide 'workspace-model)



